Fix miscompile due to SSA aliasing - #3775
Conversation
operation Main() : Int {
use q0 = Qubit();
use q1 = Qubit();
X(q0);
X(q1);
mutable n = 0;
if MResetZ(q0) == One {
n = 1;
}
let h = n;
if MResetZ(q1) == One {
n = 2;
}
h + n
}Expected: 3 Speculative explanation (copilot): At ssa_transform.rs:167, only Shallow(n) aliases are redirected when the earlier phi for n is created. An alias that is still Deep(n) remains tied to the mutable ID. Later, ssa_transform.rs:190 can overwrite the shallow mapping created by a branch-local mutation. |
This is the resolved in the latest changes. |
This change updates variable mapping logic in RIR passes to differentiate between "strong" and "weak" mappings, where the former indicates the mapping should be followed through successive links until the terminator operand is reached and the latter indicates no further mapping should be performed. Fixes #3769
91b8977 to
eb677c1
Compare
Andrew Casey (amcasey)
left a comment
There was a problem hiding this comment.
I'm not super familiar with this code, but the explanation made sense and I couldn't find any remaining issues in buddy testing.
This change updates variable mapping logic in RIR passes to differentiate between "deep" and "shallow" mappings, where the former indicates the mapping should be followed through successive links until the terminator operand is reached and the latter indicates no further mapping should be performed. Fixes #3769